package com.lovol.gis.demo.common;

import java.io.Serializable;

public class ResultResponse<T> implements Serializable {
    private static final long serialVersionUID = 8708569195046968619L;
    private Boolean success = true;
    private Integer code;
    private String message;
    private T result;
    private long timestamp = System.currentTimeMillis();

    private ResultResponse() {
        this.setCode(ResultEnum.SUCCESS.getCode());
        this.setMessage(ResultEnum.SUCCESS.getMsg());
    }

    public static <T> ResultResponse<T> ok() {
        return new ResultResponse();
    }

    public static <T> ResultResponse<T> ok(T data) {
        ResultResponse<T> resultResponse = new ResultResponse();
        resultResponse.setSuccess(true);
        resultResponse.setResult(data);
        return resultResponse;
    }

    public static <T> ResultResponse<T> fail() {
        ResultResponse<T> resultResponse = new ResultResponse();
        resultResponse.setCode(ResultEnum.FAILURE.getCode());
        resultResponse.setMessage(ResultEnum.FAILURE.getMsg());
        resultResponse.setSuccess(false);
        return resultResponse;
    }

    public static <T> ResultResponse<T> fail(String msg) {
        ResultResponse<T> resultResponse = new ResultResponse();
        resultResponse.setCode(ResultEnum.FAILURE.getCode());
        resultResponse.setMessage(msg);
        resultResponse.setSuccess(false);
        return resultResponse;
    }

    public static <T> ResultResponse<T> fail(ResultEnum resultEnum) {
        ResultResponse<T> resultResponse = new ResultResponse();
        resultResponse.setCode(resultEnum.getCode());
        resultResponse.setMessage(resultEnum.getMsg());
        resultResponse.setSuccess(false);
        return resultResponse;
    }

    public static <T> ResultResponse<T> fail(Integer code, String msg) {
        ResultResponse<T> resultResponse = new ResultResponse();
        resultResponse.setCode(code);
        resultResponse.setMessage(msg);
        resultResponse.setSuccess(false);
        return resultResponse;
    }

    public Boolean getSuccess() {
        return this.success;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public T getResult() {
        return this.result;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResultResponse)) {
            return false;
        } else {
            ResultResponse<?> other = (ResultResponse)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label63: {
                    Object this$success = this.getSuccess();
                    Object other$success = other.getSuccess();
                    if (this$success == null) {
                        if (other$success == null) {
                            break label63;
                        }
                    } else if (this$success.equals(other$success)) {
                        break label63;
                    }

                    return false;
                }

                Object this$code = this.getCode();
                Object other$code = other.getCode();
                if (this$code == null) {
                    if (other$code != null) {
                        return false;
                    }
                } else if (!this$code.equals(other$code)) {
                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                label42: {
                    Object this$result = this.getResult();
                    Object other$result = other.getResult();
                    if (this$result == null) {
                        if (other$result == null) {
                            break label42;
                        }
                    } else if (this$result.equals(other$result)) {
                        break label42;
                    }

                    return false;
                }

                if (this.getTimestamp() != other.getTimestamp()) {
                    return false;
                } else {
                    return true;
                }
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof ResultResponse;
    }

    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        Object $success = this.getSuccess();
        result = result * 59 + ($success == null ? 43 : $success.hashCode());
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $result = this.getResult();
        result = result * 59 + ($result == null ? 43 : $result.hashCode());
        long $timestamp = this.getTimestamp();
        result = result * 59 + (int)($timestamp >>> 32 ^ $timestamp);
        return result;
    }

    public String toString() {
        return "ResultResponse(success=" + this.getSuccess() + ", code=" + this.getCode() + ", message=" + this.getMessage() + ", result=" + this.getResult() + ", timestamp=" + this.getTimestamp() + ")";
    }
}

